package com.heo.music.player.handler;

import com.heo.music.player.dto.base.ResponseMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.server.ResponseStatusException;

/**
 * @author 星天无极
 **/
@ControllerAdvice
@Slf4j
@Order(1)
public class ResponseStatusExceptionHandler {

    @ResponseBody
    @ExceptionHandler(ResponseStatusException.class)
    public ResponseEntity<ResponseMsg> responseStatusExceptionHandler(ResponseStatusException e) {
        log.error(e.getMessage());
        return ResponseEntity.status(e.getStatus()).body(new ResponseMsg(e.getReason()));
    }
}
